local thbattle__lingxian_sangxin = fk.CreateSkill {

  name = "thbattle__lingxian_sangxin",

  tags = { Skill.Compulsory, },

}



thbattle__lingxian_sangxin:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    return player.phase == Player.Play and player:getMark("@@thbattle__lingxian_sangxin") > 0 and card and
        card.trueName ~= "slash"
  end,
  is_prohibited = function(self, from, to, card)
    local room = Fk:currentRoom()
    if from:getMark("@@thbattle__lingxian_sangxin") > 0 and card and from.phase == Player.Play and card.trueName == "slash" then
      if to then
        local room = Fk:currentRoom()
        local player = from
        ---获取最近距离
        local n = 999
        for _, p in ipairs(room.alive_players) do
          if p ~= player and player:distanceTo(p) < n then
            n = player:distanceTo(p)
          end
        end
        ---
        ---找最近距离的角色
        local targets = table.map(table.filter(room.alive_players, function(p)
          return player:distanceTo(p) == n
        end), function(p) return p.id end)
        return not table.contains(targets, to.id)
      end
    end
  end,
})

thbattle__lingxian_sangxin:addEffect(fk.EventPhaseStart, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@thbattle__lingxian_sangxin") > 0 and player.phase == Player.Finish
  end,
  on_refresh = function(self, event, target, player, data)
    LoR_Utility.removeStatusMark(player, "@@thbattle__lingxian_sangxin")
    player.room:handleAddLoseSkills(player, "-thbattle__lingxian_sangxin", nil, true, false)
  end,
})

return thbattle__lingxian_sangxin